package com.telit.android.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.telit.android.service.ICommEventTaskTrackService;
import com.telit.common.entity.CommEventTaskTrack;
import com.telit.common.entity.DataReturn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 事件任务巡护关联表 前端控制器
 * </p>
 *
 * @author yummy
 * @since 2022-04-22
 */
@RestController
@RequestMapping("/comm-event-task-track")
@Api(tags = "事件任务巡护关联表",description = "/comm-event-task-track")
public class CommEventTaskTrackController {

    private Logger log = LoggerFactory.getLogger(getClass());

    @Resource
    private ICommEventTaskTrackService commEventTaskTrackService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public DataReturn add(@RequestBody CommEventTaskTrack commEventTaskTrack){
        long value= commEventTaskTrackService.add(commEventTaskTrack);
        return DataReturn.ok(value);
    }

    @GetMapping("/delete/{id}")
    @ApiImplicitParam(name = "id",value = "配置ID",paramType = "path",dataType = "Integer")
    public DataReturn delete(@PathVariable("id") Integer id){
        int value= commEventTaskTrackService.delete(id);
        return DataReturn.ok(value);
    }

    @GetMapping("/deleteBatch")
    @ApiImplicitParam(name = "ids",value = "配置ID数组",paramType = "query",dataType = "integer[]")
    public DataReturn deleteBatch(Integer[] ids){
        List<Integer> values= commEventTaskTrackService.deleteBatch(ids);
        return DataReturn.ok(values);
    }

    @PostMapping("/updateCommEventTaskTrackByParam")
    @ApiOperation("修改")
    public DataReturn updateCommEventTaskTrackByParam(@RequestBody CommEventTaskTrack commEventTaskTrack){
        commEventTaskTrackService.updateCommEventTaskTrackByParam(commEventTaskTrack);
        return DataReturn.ok();
    }

    @PostMapping("/search")
    @ApiOperation("条件查询+分页")
    @ApiImplicitParams({@ApiImplicitParam(name="page",value="当前页面",dataType = "int",paramType = "query"),
    @ApiImplicitParam(name="rows",value = "每页记录数",dataType = "int",paramType = "query")})
    public DataReturn findListByPage(@RequestBody(required = false) CommEventTaskTrack commEventTaskTrack, Integer page,
                                     Integer pageCount){
        IPage<CommEventTaskTrack> commEventTaskTrackPage = commEventTaskTrackService.findListByPage(commEventTaskTrack,page, pageCount);
        Map<String,Object> retMap=new HashMap<String,Object>();
        retMap.put("commEventTaskTrack",commEventTaskTrackPage.getRecords());
        retMap.put("total",commEventTaskTrackPage.getTotal());
        return DataReturn.ok(retMap);
    }

    @PostMapping("/searchNoPage")
    @ApiOperation("条件查询")
    public DataReturn searchNoPage(@RequestBody(required = false) CommEventTaskTrack commEventTaskTrack){
        List<CommEventTaskTrack> commEventTaskTrackList = commEventTaskTrackService.searchNoPage(commEventTaskTrack);
        return DataReturn.ok(commEventTaskTrackList);
    }

    @GetMapping("/findOne/{id}")
    @ApiOperation("根据id获取配置实体")
    @ApiImplicitParam(name = "id",value = "配置ID",paramType = "path",dataType = "Long")
    public DataReturn findById(@PathVariable Integer id){
        CommEventTaskTrack commEventTaskTrack= commEventTaskTrackService.findById(id);
        return DataReturn.ok(commEventTaskTrack);
    }

    @GetMapping("/selectIdByTaskIdAndStatus")
    @ApiOperation("根据id获取配置实体")
    public DataReturn selectIdByTaskIdAndStatus(@RequestParam("taskId") Long taskId,@RequestParam("status") String status,@RequestParam("forestkeeperId") Long forestkeeperId){
        List<Long> commEventTaskTrackIdList= commEventTaskTrackService.selectIdByTaskIdAndStatus(taskId,status,forestkeeperId);
        return DataReturn.ok(commEventTaskTrackIdList);
    }
}
